/**
 * Copyright 2009 Erick Armbrust 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0 
 *   
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS, 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and 
 * limitations under the License. 
 */

package tapioca.dt;

import java.util.Set;

import tapioca.testing.AppEngineTestCase;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.repackaged.com.google.common.collect.Sets;

/**
 * Tests for the {@link GetRequest} class.
 *
 * @author armbrust@gmail.com (Erick Armbrust)
 */
public class GetRequestTest extends AppEngineTestCase {

  public void testEquals() {
    Key k1 = KeyFactory.createKey("foo", 1L);
    Key k2 = KeyFactory.createKey("foo", 1L);
    
    GetRequest g1 = new GetRequest(k1, k2);
    GetRequest g2 = new GetRequest(k1, k2);
    GetRequest g3 = new GetRequest(k1, null);
    
    assertEquals(g1, g1);
    assertEquals(g1, g2);
    assertFalse(g1.equals(g3) || g2.equals(g3));
    assertFalse(g1.equals(new Object()));
  }
  
  public void testHashCode() {
    Key k1 = KeyFactory.createKey("foo", 1L);
    Key k2 = KeyFactory.createKey("foo", 1L);
    
    GetRequest g1 = new GetRequest(k1, k2);
    GetRequest g2 = new GetRequest(k1, k2);
    GetRequest g3 = new GetRequest(k1, null);
    
    assertEquals(g1.hashCode(), g1.hashCode());
    assertEquals(g1.hashCode(), g2.hashCode());
    assertFalse(g1.hashCode() == g3.hashCode() || g2.hashCode() == g3.hashCode());
    
    Set<GetRequest> set = Sets.newHashSet(g1, g2, g3);
    assertEquals(2, set.size());
    assertTrue(set.contains(g1));
    assertTrue(set.contains(g2));
    assertTrue(set.contains(g3));
  }
  
}
